import { FileChangeUtil } from "./FileChangeUtil";
import { Main } from "../Main";
import { ConfigUtil } from "./ConfigUtil";
import * as fs from "fs";
import { SyncResExecUtil } from "./SyncResExecUtil";
import { FastFileChangeUtil } from "./FastFileChangeUtil";
import { SyncResInfoUtil } from "./SyncResInfoUtil";

/**
 * 快速资源同步，找出需要操作的文件，只找不操作
 * @author 赵占涛
 */
export class FastSyncResInfoUtil {
    /**
     * 找出需要操作的文件
     */
    static getChangeList(type:"normal"|"ios"|"android", cb: (exportList: string[], deleteList: string[]) => void) {
        FastFileChangeUtil.changed(Main.codePath + "Resources/cocosstudio/cocosstudio/", (sourceChange: string[], sourceAdd: string[], sourceDelete: string[]) => {
            let resTmpPath = type == "normal" ? "res/" : (type == "ios" ? "resPlatform/resIos/" : "resPlatform/resAndroid/");
            FastFileChangeUtil.changed(Main.codePath + "Resources/" + resTmpPath, (outputChange: string[], outputAdd: string[], outputDelete: string[]) => {
                // console.log(sourceChange, sourceAdd, sourceDelete);
                // console.log(outputChange, outputAdd, outputDelete);

                // 需要导出的
                let needExportObj: { [key: string]: true } = {};
                // 需要删除的
                let needDeleteObj: { [key: string]: true } = {};
                SyncResInfoUtil.funcSourceChange(needExportObj, needDeleteObj, sourceChange);
                SyncResInfoUtil.funcSourceChange(needExportObj, needDeleteObj, sourceAdd);
                SyncResInfoUtil.funcSourceDelete(needExportObj, needDeleteObj, sourceDelete);
                SyncResInfoUtil.funcOutputChange(type, needExportObj, needDeleteObj, outputChange);
                SyncResInfoUtil.funcOutputChange(type, needExportObj, needDeleteObj, outputAdd);
                SyncResInfoUtil.funcOutputDelete(type, needExportObj, needDeleteObj, outputDelete);

                cb(Object.keys(needExportObj), Object.keys(needDeleteObj));
            });
        });
    }
}